import { addPropertyfeeAPI, deletePropertyfeeAPI, fetchBuildingListAPI, fetchEnterpriseListAPI, fetchPropertyfeeListAPI } from '@/api/propety/propetyApi';

const actions = {
  /* 发送请求获取物业费列表的action */
  async fetchPropertyfeeList(context, pageParams) {
    const { data } = await fetchPropertyfeeListAPI(pageParams);
    context.commit('updatePropertyfeeList', data);
  },
  /* 发送请求删除物业费的接口 */
  async deletePropertyfee(context, id) {
    await deletePropertyfeeAPI(id);
    return '删除物业费成功';
  },
  /* 发送请求添加物业费的action */
  async addPropertyfee(context, formData) {
    await addPropertyfeeAPI(formData);
    return '添加物业费成功';
  },
  /* 发送请求获取楼宇列表的action */
  async fetchBuildingList(context) {
    const { data } = await fetchBuildingListAPI();
    context.commit('updateBuildingList', data);
  },
  /* 发送请求获取租户列表的action */
  async fetchEnterpriseList(context) {
    const { data } = await fetchEnterpriseListAPI();
    context.commit('updateEnterpriseList', data);
  },
};
const mutations = {
  /* 更新物业费列表的mutation */
  updatePropertyfeeList(state, propertyfeeListInfo) {
    state.propertyfeeListInfo = propertyfeeListInfo;
  },
  /* 更新楼宇列表的mutation */
  updateBuildingList(state, buildingList) {
    state.buildingList = buildingList;
  },
  /* 更新租户列表的mutation */
  updateEnterpriseList(state, enterpriseList) {
    state.enterpriseList = enterpriseList;
  },
};
const state = () => {
  return {
    propertyfeeListInfo: {},
    buildingList: [],
    enterpriseList: [],
  };
};

const getters = {
  propertyfeeList: state => state.propertyfeeListInfo.rows,
  total: state => state.propertyfeeListInfo.total,
};

export default {
  actions,
  mutations,
  state,
  getters,
  namespaced: true,
};
